package com.neuedu.dao.impl;

import com.neuedu.common.DBUtil;
import com.neuedu.dao.BaseDao;
import com.neuedu.dao.DeptClassityDao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class DeptClassityDaoImpl extends BaseDao implements DeptClassityDao {
    @Override
    public List<Map<String, Object>> getAllDeptClassity(String sql) {
        Connection con= DBUtil.getCon();
        return this.querySql(con,sql);
    }

    @Override
    public int delclassify(Object[] objs) {
        String sql="DELETE FROM deptclassify WHERE id=?";
        String sql1="DELETE FROM deptment WHERE deptclassifyid=?";
        Connection con= DBUtil.getCon();
        int flag=0;
        int flag1=0;
        try {
            flag=this.delUpins(sql,objs,con);
            flag1=this.delUpins(sql1,objs,con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public int addClassify(Object[] objs) {
        String sql="INSERT INTO deptclassify VALUES(?,?)";
        Connection con = DBUtil.getCon();
        int flag=0;
        try {
            flag=this.delUpins(sql,objs,con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public int updateClassify(Object[] objs) {
        String sql="UPDATE deptclassify SET classifyname=? WHERE id=?";
        Connection con = DBUtil.getCon();
        int flag=0;
        try {
            flag=this.delUpins(sql,objs,con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public List<Map<String, Object>> getLikeDeptClassity(String sql,Object[] objs) {
        Connection con= DBUtil.getCon();
        List<Map<String, Object>> list = null;
        try {
            list = this.queryParmSqlAsName(sql,objs,con);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
}
